package com.lgy.core.task;

import com.lgy.comm.Constant;
import com.lgy.core.JobService;
import com.lgy.core.base.AbstractTask;
import com.lgy.model.ServInfo;
import com.lgy.service.ServInfoService;
import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



/**
 * Leader的定时任务类
 * @author yuejing
 * @date 2015年3月29日 下午10:05:34
 * @version V1.0.0
 */
@Component
public class LeaderTask extends AbstractTask {

	private static final Logger LOGGER = Logger.getLogger(LeaderTask.class);

	@Autowired
	private ServInfoService servInfoService;

	@Override
	public void execute(JobExecutionContext context) {
		System.out.println("=========================== LeaderTask ====================");
		//Leader的任务
		try {
			//Leader选举和获取当前Leader
			ServInfo servInfo = servInfoService.chooseLeader();

			if(servInfo != null && servInfo.getServid().equals(Constant.serviceCode())) {
				System.out.println("这是leader");
			}
		} catch (Exception e) {
			LOGGER.error("负载均衡异常: " + e.getMessage(), e);
		}

	}
}